#
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright © 2019 Keith Packard
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
option('fast-strcmp', type: 'boolean', value: true,
       description: 'Always optimize strcmp for performance')

option('have-alias-attribute', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'Compiler supports __alias__ attribute')

option('have-format-attribute', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'Compiler supports __format__ attribute')

option('have-weak-attribute', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'Compiler supports __weak__ attribute')

option('multilib', type: 'boolean', value: true,
       description: 'Enable multilib compile')

option('multilib-list', type: 'array', value: [],
       description: 'List of multilib configurations to build for')

option('multilib-exclude', type: 'array', value: [],
       description: 'Multilib configurations containing any of these strings will not be built')

option('build-type-subdir', type: 'string',
       description: 'Build-type subdir. Also skips installing .specs file')

option('picolib', type: 'boolean', value: true,
       description: 'Include pico lib bits')

option('picocrt', type: 'boolean', value: true,
       description: 'Include pico crt bits')

option('picocrt-enable-mmu', type: 'boolean', value: true,
       description: 'Enable memory management unit in picocrt startup')

option('picocrt-lib', type: 'boolean', value: true,
       description: 'Include pico crt bits in lib form')

option('semihost', type: 'boolean', value: true,
       description: 'Include semihost bits')

option('specsdir', type: 'string',
       description: 'Installation directory for .specs file')

option('sysroot-install', type: 'boolean', value: false,
       description: 'Install in gcc sysroot')

option('sysroot-install-skip-checks', type: 'boolean', value: false,
       description: 'Skip sysroot path checks during config')

option('system-libc', type: 'boolean', value: false,
       description: 'Install as system C library')
					      
option('picoexit', type: 'boolean', value: true,
       description: 'Smaller exit/atexit/onexit code')

option('sanitize-bounds', type: 'boolean', value: false,
       description: 'Build the library with -fsanitize=bounds')

option('sanitize-trap-on-error', type: 'boolean', value: false,
       description: 'Build the library with -fsanitize-undefined-trap-on-error')

option('use-stdlib', type: 'boolean', value: false,
       description: 'Do not bypass the standard system library with -nostdlib (useful for native testing)')

option('profile', type: 'boolean', value: false,
       description: 'Enable profiling by adding -pg -no-pie to compile flags')

option('freestanding', type: 'boolean', value: false,
       description: 'Build the library with -ffreestanding (useful for Zephyr testing)')

option('analyzer', type: 'boolean', value: false,
       description: 'Enable the analyzer while compiling with -fanalyzer')

option('assert-verbose', type: 'boolean', value: true,
       description: 'Assert provides verbose information')

#
# Testing options
#
option('native-tests', type: 'boolean', value: false,
       description: 'Run some tests against native libc too')
option('native-math-tests', type: 'boolean', value: true,
       description: 'Run math tests against native libm when native-tests is enable')
option('tests', type: 'boolean', value: false,
       description: 'Enable tests')
option('tests-cdefs', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'Enable test of sys/cdefs.h. If set to auto, enable when tests are enabled')
option('tests-enable-stack-protector', type: 'boolean', value: true,
       description: 'tests enable stack protector')
option('tests-enable-full-malloc-stress', type: 'boolean', value: false,
       description: 'tests enable stress test for full malloc')
option('tests-enable-posix-io', type: 'boolean', value: true,
       description: 'tests enable posix-io when available')
option('test-long-double', type: 'boolean', value: true,
       description: 'Enable long double tests on targets with long double type')
option('split-large-tests', type: 'boolean', value: false,
       description: 'Split large tests into pieces for smaller targets')
option('test-stdin', type: 'boolean', value: false,
       description: 'Enable tests that use stdin. This only works on a few targets')
option('fortify-source', type: 'combo', choices: ['none', '1', '2', '3'], value: '3',
       description: 'Set _FORTIFY_SOURCE=<value> when building tests')
option('test-machine', type: 'string', value: 'qemu',
       description: 'Machine-specific startup code to use when running tests')


option('tinystdio', type: 'boolean', value: true,
       description: 'Use tiny stdio from avr libc')

#
# Options applying to both legacy stdio and tinystdio
#
option('io-c99-formats', type: 'boolean', value: true,
       description: 'enable C99 support in IO functions like printf/scanf')
option('newlib-io-c99-formats', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable C99 support in IO functions like printf/scanf')
option('io-long-long', type: 'boolean', value: false,
       description: 'enable long long type support in IO functions like printf/scanf')
option('newlib-io-long-long', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable long long type support in IO functions like printf/scanf')
option('io-pos-args', type: 'boolean', value: false,
       description: 'enable printf-family positional arg support (always enabled for tinystdio float)')
option('newlib-io-pos-args', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable printf-family positional arg support (always enabled for tinystdio float)')
option('io-long-double', type: 'boolean', value: false,
       description: 'enable long double type support in IO functions printf/scanf')
option('newlib-io-long-double', type: 'boolean', value: false,
       description: 'enable long double type support in IO functions printf/scanf')

#
# Options applying only to tinystdio
#
option('io-float-exact', type: 'boolean', value: true,
       description: 'use float/string code which supports round-tripping')
option('atomic-ungetc', type: 'boolean', value: true,
       description: 'use atomics in fgetc/ungetc to make them re-entrant')
option('posix-io', type: 'boolean', value: true,
       description: 'Provide fopen/fdopen using POSIX I/O (open, close, read, write, lseek)')
option('posix-console', type: 'boolean', value: false,
       description: 'Use POSIX I/O for stdin/stdout/stderr')
option('format-default', type: 'combo', choices: ['double', 'float', 'long-long', 'integer', 'minimal'], value: 'double',
       description: 'which printf/scanf versions should be the default')
option('printf-aliases', type: 'boolean', value: true,
       description: 'Allow link-time printf aliases')
option('io-percent-b', type: 'boolean', value: false,
       description: 'enable proposed %b/%B format in printf and scanf in tinystdio (default: false)')
option('printf-small-ultoa', type: 'boolean', value: true,
       description: 'Avoid softare division in decimal conversions')
option('printf-percent-n', type: 'boolean', value: false,
       description: 'Support %n in printf format strings (default: false)')
option('minimal-io-long-long', type: 'boolean', value: false,
       description: 'enable long long type support in minimal printf/scanf')
option('fast-bufio', type: 'boolean', value: false,
       description: 'enable some faster buffered i/o operations')
option('io-wchar', type: 'boolean', value: false,
       description: 'enable wide character support in printf/scanf (requires multi-byte support)')

#
# Options applying to only legacy stdio
#
option('newlib-elix-level', type: 'integer', value: 4,
       description: 'desired elix library level (0-4)')
option('newlib-fseek-optimization', type: 'boolean', value: false,
       description: 'enable fseek optimization')
option('newlib-fvwrite-in-streamio', type: 'boolean', value: false,
       description: 'disable iov in streamio')
option('newlib-global-stdio-streams', type: 'boolean', value: false,
       description: 'enable global stdio streams')
option('newlib-io-float', type: 'boolean', value: false,
       description: 'enable printf/scanf family float support')
option('newlib-nano-formatted-io', type: 'boolean', value: false,
       description: 'Use nano version formatted IO')
option('newlib-reent-small', type: 'boolean', value: false,
       description: 'enable small reentrant struct support')
option('newlib-stdio64', type: 'boolean', value: true,
       description: 'Include stdio64 with newlib stdio')
option('newlib-unbuf-stream-opt', type: 'boolean', value: false,
       description: 'enable unbuffered stream optimization in streamio')
option('newlib-wide-orient', type: 'boolean', value: false,
       description: 'Turn off wide orientation in streamio')
option('newlib-have-fcntl', type: 'boolean', value: false,
       description: 'System has fcntl function')

#
# Internationalization options
#

option('mb-capable', type: 'boolean', value: false,
       description: 'enable multibyte support for UTF-8 charset')
option('mb-extended-charsets', type: 'boolean', value: false,
       description: 'enable additional ISO, Windows and JIS charsets')
option('mb-ucs-charsets', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable additional UCS encodings')
option('mb-iso-charsets', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable ISO-8859 encodings')
option('mb-jis-charsets', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable additional JIS multibyte encodings')
option('mb-windows-charsets', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto',
       description: 'enable additional Windows encodings')

option('newlib-mb', type: 'boolean', value: false,
       description: 'enable multibyte support [deprecated, use mb-capable]')

#
# Startup/shutdown options
#
option('lite-exit', type: 'boolean', value: true,
       description: 'enable light weight exit')
option('newlib-atexit-dynamic-alloc', type: 'boolean', value: false,
       description: 'enable dynamic allocation of atexit entries')
option('newlib-global-atexit', type: 'boolean', value: false,
       description: 'enable atexit data structure as global')
option('newlib-initfini', type: 'boolean', value: true,
       description: 'Supports _init() and _fini()')
option('newlib-initfini-array', type: 'boolean', value: true,
       description: 'compiler supports INIT_ARRAY section types')
option('newlib-register-fini', type: 'boolean', value: false,
       description: 'enable finalization function registration using atexit')
option('fake-semihost', type: 'boolean', value: false,
       description: 'create fake semihost library to link tests')
option('crt-runtime-size', type: 'boolean', value: false,
       description: 'compute crt memory space sizes at runtime')
option('atomic-signal', type: 'boolean', value: true,
       description: 'use atomics in signal/raise to make them re-entrant')

#
# Malloc option
#
option('newlib-nano-malloc', type: 'boolean', value: true,
       description: 'use small-footprint nano-malloc implementation')
option('nano-malloc-clear-freed', type: 'boolean', value: false,
       description: 'nano version erases memory on free/realloc')

#
# Locking support
#
option('newlib-multithread', type: 'boolean', value: true,
       description: 'enable support for multiple threads')
option('newlib-retargetable-locking', type: 'boolean', value: true,
       description: 'Allow locking routines to be retargeted at link time')

#
# Thread-local storage support
#
option('thread-local-storage', type: 'combo', choices: ['true', 'false', 'auto', 'picolibc'], value: 'picolibc',
       description: 'use thread local storage for static data ("picolibc": picolibc and toolchain support) ("auto": toolchain supports) (default: "picolibc")')
option('tls-model', type: 'combo', choices: ['global-dynamic', 'local-dynamic', 'initial-exec', 'local-exec'], value: 'local-exec',
       description: 'Set TLS model. No-op when thread-local-storage is false')
option('newlib-global-errno', type: 'boolean', value: false,
       description: 'use global errno variable')
option('errno-function', type: 'string',
       value: 'false',
       description: 'Use this function to compute errno address (default false, auto means autodetect, zephyr means use z_errno_wrap if !tls)')
option('tls-rp2040', type: 'boolean', value: false,
       description: 'Use Raspberry Pi RP2040 CPUID register to index thread local storage value')

#
# Math options
#
# Use "obsolete" math code, which use 'float' for 'float' functions
# instead of the newer code which uses 'double' instead.
#
option('newlib-obsolete-math', type: 'combo', choices: ['true', 'false', 'auto'],
       value: 'auto',
       description: 'Use float type for float valued math routines (default: automatic based on platform)')
option('newlib-obsolete-math-float', type: 'combo', choices: ['true', 'false', 'auto'],
       value: 'auto',
       description: 'Use old math code that uses float type for float valued math routines (default: automatic based on platform)')
option('newlib-obsolete-math-double', type: 'combo', choices: ['true', 'false', 'auto'],
       value: 'auto',
       description: 'Use old math code for double valued math routines (default: automatic based on platform)')
option('want-math-errno', type: 'boolean', value: false,
       description: 'Set errno in math functions according to stdc (default: false)')

#
# Obsolete newlib options
#
option('newlib-long-time_t', type: 'boolean', value: false,
       description: 'define time_t to long instead of a 64-bit type')
option('newlib-missing-syscall-names', type: 'boolean', value: false,
       description: 'system only provides regular syscall API')
option('newlib-reentrant-syscalls-provided', type: 'boolean', value: false,
       description: 'system provides reentrant syscall API')
option('newlib-supplied-syscalls', type: 'boolean', value: false,
       description: 'newlib supplies system call functions')
